﻿using Node.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using System.Collections;

namespace NodeTestProject
{
    
    
    /// <summary>
    ///This is a test class for IPNetworkTest and is intended
    ///to contain all IPNetworkTest Unit Tests
    ///</summary>
	[TestClass()]
	public class IPNetworkTest
	{


		private TestContext testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}

		#region Additional test attributes
		// 
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		//[ClassInitialize()]
		//public static void MyClassInitialize(TestContext testContext)
		//{
		//}
		//
		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup()]
		//public static void MyClassCleanup()
		//{
		//}
		//
		//Use TestInitialize to run code before running each test
		//[TestInitialize()]
		//public void MyTestInitialize()
		//{
		//}
		//
		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//public void MyTestCleanup()
		//{
		//}
		//
		#endregion

		/// <summary>
		///A test for SigdigitCount
		///</summary>
		[TestMethod()]
		public void SigdigitCountTest()
		{
			IPAddress ip = IPAddress.Parse("172.16.12.144");
			int order = 8;
			IPNetwork target = new IPNetwork(ip, order);

			Assert.AreEqual(24, target.SigdigitCount);
		}

		/// <summary>
		///A test for IsSingleIP
		///</summary>
		[TestMethod()]
		public void IsSingleIPTest()
		{
			IPAddress ip = IPAddress.Parse("172.16.12.144");
			int order = 0;
			IPNetwork target = new IPNetwork(ip, order);

			Assert.AreEqual(true, target.IsSingleIP);
		}

		/// <summary>
		///A test for Capacity
		///</summary>
		[TestMethod()]
		public void CapacityTest()
		{
			IPAddress ip = IPAddress.Parse("172.16.12.144");
			int order = 8;
			IPNetwork target = new IPNetwork(ip, order);

			Assert.AreEqual(256, target.Capacity);
		}

		/// <summary>
		///A test for TryParse
		///</summary>
		[TestMethod()]
		public void TryParseTest()
		{
			IPNetwork valueExpected = new IPNetwork(IPAddress.Parse("172.16.20.144"), 8); // TODO: Initialize to an appropriate value

			string input = "172.16.20.144/24";
			IPNetwork value;
			Assert.IsTrue(IPNetwork.TryParse(input, out value));
			Assert.AreEqual(value, valueExpected);
		}

		/// <summary>
		///A test for ToString
		///</summary>
		[TestMethod()]
		public void ToStringTest()
		{
			IPAddress ip = IPAddress.Parse("172.16.12.144");
			int order = 8;
			IPNetwork target = new IPNetwork(ip, order);

			Assert.AreEqual("172.16.12.0/24", target.ToString());
		}

		/// <summary>
		///A test for Parse
		///</summary>
		[TestMethod()]
		public void ParseTest()
		{
			IPNetwork expected = new IPNetwork(IPAddress.Parse("172.16.20.144"), 8);

			string input = "172.16.20.144/24";
			IPNetwork actual = IPNetwork.Parse(input);

			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for GetHashCode
		///</summary>
		[TestMethod()]
		public void GetHashCodeTest()
		{
			IPNetwork net1 = new IPNetwork(IPAddress.Parse("172.16.20.144"), 8);
			IPNetwork net2 = new IPNetwork(IPAddress.Parse("172.16.20.44"), 8);

			Assert.AreEqual(net1.GetHashCode(), net2.GetHashCode());
		}

		/// <summary>
		///A test for Equals
		///</summary>
		[TestMethod()]
		public void EqualsTestNetwork()
		{
			IPNetwork net1 = new IPNetwork(IPAddress.Parse("172.16.20.144"), 8);
			IPNetwork net2 = new IPNetwork(IPAddress.Parse("172.16.20.44"), 8);

			Assert.AreEqual(net1, net2);
		}

		/// <summary>
		///A test for Equals
		///</summary>
		[TestMethod()]
		public void EqualsTestIP()
		{
			IPNetwork net = new IPNetwork(IPAddress.Parse("172.16.20.144"), 0);
			var ip = IPAddress.Parse("172.16.20.144");

			Assert.IsTrue(net.Equals(ip));
		}

		/// <summary>
		///A test for Equals
		///</summary>
		[TestMethod()]
		public void EqualsTestObject()
		{
			IPNetwork net1 = new IPNetwork(IPAddress.Parse("172.16.20.144"), 8);
			object net2 = new IPNetwork(IPAddress.Parse("172.16.20.44"), 8);

			Assert.IsTrue(net1.Equals(net2));
		}

		/// <summary>
		///A test for Contains
		///</summary>
		[TestMethod()]
		public void ContainsTestIP()
		{
			IPNetwork net = new IPNetwork(IPAddress.Parse("172.16.20.144"), 8);
			var ip = IPAddress.Parse("172.16.20.44");

			Assert.IsTrue(net.Contains(ip));
		}

		/// <summary>
		///A test for Contains
		///</summary>
		[TestMethod()]
		public void ContainsTestNetwork()
		{
			IPNetwork net1 = new IPNetwork(IPAddress.Parse("172.16.20.144"), 8);
			IPNetwork net2 = new IPNetwork(IPAddress.Parse("172.16.20.44"), 16);

			Assert.IsTrue(net1.Contains(net1));
		}

		/// <summary>
		///A test for IPNetwork Constructor
		///</summary>
		[TestMethod()]
		public void IPNetworkConstructorTest()
		{
			IPNetwork net = new IPNetwork(IPAddress.Parse("172.16.20.144"), 8);

			Assert.AreEqual(net.ToString(), "172.16.20.0/24");
		}
	}
}
